﻿#region Copyright Notices
// This library is free software; you can redistribute it and/or
// modify it under the terms of the GNU Library General Public
// License as published by the Free Software Foundation; either
// version 2 of the License, or (at your option) any later version.
//
// This library is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
// Library General Public License for more details.
// 
// You should have received a copy of the GNU Library General Public
// License along with this library; if not, write to the Free
// Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
#endregion

using System;
using System.Windows.Media;

namespace Yarr.YarrPad
{
    public enum TextType
    {
        Default,
        Input,
        Prompt,
        Output,
        Error,
        Header,
        Result,
        DebugOut
    }

    internal static class TextColors
    {
        private static readonly Color[] colors = new Color[Enum.GetNames(typeof(TextType)).Length];

        public static Color GetColor(TextType type)
        {
            return EnsureColor(type);
        }

        private static Color EnsureColor(TextType type)
        {
            int index = (int) type;
            if ((index < 0) || (index >= colors.Length))
            {
                return default(Color);
            }
            lock (colors.SyncRoot)
            {
                if ( colors[index] == default(Color))
                {
                    Color color = CreateColor(type);
                    colors[index] = color;
                }
            }
            return colors[(int) type];
        }

        private static Color CreateColor(TextType type)
        {
            switch (type)
            {
                case TextType.Default:
                case TextType.Input:
                default:
                {
                    return Colors.Black;
                }

                case TextType.Prompt:
                {
                    return Colors.DarkSlateGray;
                }

                case TextType.Output:
                {
                    return Colors.Blue;
                }

                case TextType.Error:
                {
                    return Color.FromRgb(192, 0, 0);
                }

                case TextType.DebugOut:
                case TextType.Header:
                {
                    return Colors.Gray;
                }

                case TextType.Result:
                {
                    return Colors.Green;
                }
            }
        }
    }
}
